//
//  SXStatusCellTopView.swift
//  微博09项目
//
//  Created by mac on 15/9/8.
//  Copyright © 2015年 itcast. All rights reserved.
//

import UIKit
import SDWebImage

class SXStatusCellTopView: UIView {
    var statusViewModel:SXStatusViewModel?{
        didSet{
            //TODO:设置界面数据
            nameLabel.text = statusViewModel?.status.user?.name
            memberView.image = statusViewModel?.userMemberImage
            vipView.image = statusViewModel?.userVipImage
            iconView.sd_setImageWithURL(statusViewModel!.stringUrlIcon)
            
            //TODO:后续处理
        
//            timeLabel.text = statusViewModel?.status.created_at
//            sourceLabel.text = statusViewModel?.status.source
            
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        //设置topView的填充颜色
        backgroundColor = UIColor.whiteColor()
        //添加子控件
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(memberView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(vipView)
       
        //给控件添加约束
        let offSet = CGPoint(x: SXStatusCellMargin, y: 0)
        iconView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSize(width: SXStatusIconWidth, height: SXStatusIconWidth), offset: CGPoint(x: SXStatusCellMargin, y: SXStatusCellMargin))
        nameLabel.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: iconView, size: nil, offset: offSet)
        memberView.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: nameLabel, size: nil, offset: offSet)
        timeLabel.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: offSet)
        sourceLabel.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: timeLabel, size: nil, offset: offSet)
        vipView.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: -8, y: 8))
    }
    
    //懒加载控件
 /// 加载头像
    private lazy var iconView:UIImageView = UIImageView(image: UIImage(named: "avatar_default_big"))
 /// 加载名称
    private lazy var nameLabel:UILabel = UILabel(title: "姓名", color: UIColor.darkGrayColor(), fontSize: 14)
/// 加载小会员图
    private lazy var memberView:UIImageView = UIImageView(image: UIImage(named: "common_icon_membership_level1"))
 /// 发送微博的时间
    private lazy var timeLabel:UILabel = UILabel(title: "刚刚", color: UIColor.darkGrayColor(), fontSize: 10)
/// 微博的来源
    private lazy var sourceLabel:UILabel = UILabel(title: "来自 新浪微博", color: UIColor.darkGrayColor(), fontSize: 10)
    private lazy var vipView:UIImageView = UIImageView(image: UIImage(named: "avatar_vip"))
 
}
